<?php

include('../__global.php');

class adm_home extends admin_ctrl
{
    function run()
    {
    	die('welcome');
    }
    
    function page_update_currency()
    {
        echo '更新中，请稍候...<br/><br/><br/>';
        flush();
        
        $currency = helper_money_trans::usd2cny();
        if($currency == false)
            die('更新失败，<a href="?page=update_currency">重试</a>');
            
        $s_php = '<?php return '.$currency.'; ?>';
        $path = K5_CONFIG_PATH.'/currency_usd2cny.php';
        $fp = fopen($path , 'w');
        fwrite($fp , $s_php);
        fclose($fp);
        
        echo '更新成功！<br/>当前美元->人民币汇率为:'.$currency;
        die;
    }
    
    function page_notice()
    {
        $data = K::config('notice_data');
        $this->output($data);
    }
    
    function api_notice()
    {
    	$notice = $this->input('notice');
    	$notice_eng = $this->input('notice_eng');
    	$data = array(
    		'notice' => $notice,
    		'notice_eng' => $notice_eng
    	);
    	$config_path = K5_CONFIG_PATH.'/notice_data.php';
    	helper_filesystem::rewrite_php_return_array_config($config_path , $data);
    	
    	
    	$oUpload = new lib_uploader();
    	
    	$img_path = K5_DATA_PATH.'/notice.jpg';
    	if($oUpload->is_set('pic'))
    	{
    		$oUpload->start('pic');
    		$oUpload->set_file_name('notice.jpg' , false);
    		$oUpload->set_save_dir(K5_DATA_PATH);
    		$oUpload->save(true);
    		
    		$oResize = new lib_imageResize();
    		$oResize->set_dest_image($img_path);
    		$oResize->set_source_image($img_path);
    		$oResize->set_max_size(160);
    		$oResize->resize();
    	}
    	
    	$this->_redirect('?page=notice');
    }
}

new adm_home();
?>